import {FileInfo} from "@/types/file-upload";
import {TextType} from "@/types/message-type";
import {ChatMessage} from "@/types/chat-message";
import {SessionType} from "@/types/chat-session";

export const MessageResponseStatus = {
    // ====== 基础成功类 ======
    SUCCESS: 0,
    PENDING: 1,

    // ====== 客户端错误类 ======
    INVALID_PARAM: 1000,
    UNAUTHORIZED: 1001,
    FORBIDDEN: 1002,
    TOKEN_EXPIRED: 1003,
    USER_NOT_FOUND: 1004,
    BLOCKED: 1005,
    STRANGER_CHAT_NOT_ALLOWED: 1006,

    // ====== 消息相关错误 ======
    SESSION_NOT_FOUND: 2000,
    MESSAGE_RECALLED: 2001,
    MESSAGE_BLOCKED: 2002,
    MESSAGE_DUPLICATE: 2003,
    MESSAGE_TOO_LARGE: 2004,
    UNSUPPORTED_TYPE: 2005,

    // ====== 系统或服务类错误 ======
    SERVER_ERROR: 5000,
    RATE_LIMITED: 5001,
    SERVICE_UNAVAILABLE: 5002,
    SERIALIZATION_ERROR: 5003,

    // ====== 系统通知类（非错误） ======
    SYSTEM_NOTICE: 9000,
    MESSAGE_RECALLED_NOTIFY: 9001,
} as const;

export type MessageResponseStatus =
    (typeof MessageResponseStatus)[keyof typeof MessageResponseStatus];

export const MessageOperation = {
    /** 发送消息 */
    SENT: 0,
    /** 接收消息 */
    RECEIVE: 1,
    /** 撤回消息 */
    REVOKE: 2,
    /** 通知消息 */
    NOTIFY: 3,
    /** 离线推送消息 */
    OFFLINE: 4,
} as const;

export type MessageOperation =
    (typeof MessageOperation)[keyof typeof MessageOperation];

/**
 * WebSocket消息发送对象
 */
export interface ChatMessageSendDTO<
    T extends FileInfo | TextType,
    P extends FileInfo | TextType
> extends Omit<ChatMessage<T, P>, "revokeStatus" | "system" | "status"> {
    /** 会话类型 */
    sessionType: SessionType;
}

export interface ChatMessageVo<
    T extends FileInfo | TextType,
    P extends FileInfo | TextType
> extends ChatMessage<T, P> {
    /** 会话类型 */
    sessionType: SessionType;
    /** 消息操作类型 */
    operation: MessageOperation;
}

/**
 * 通用WebSocket消息响应类型
 */
export interface WebSocketResponse {
    /** 消息状态码 */
    code: MessageResponseStatus;
    /** 提示信息 */
    message: string;
    /** 消息操作类型 */
    operation: MessageOperation;
    /** 关联的消息ID，可选 */
    messageId?: string | number;
}

/**
 * 会话心跳消息传输对象
 */
export interface WebSocketChatSessionHeartBeatMessageDTO {
    /**
     * 会话ID
     */
    sessionId: string;
    /**
     * 用户是否正在进行输入操作
     */
    typing: boolean;
}

/**
 * 会话心跳消息响应对象
 */
export interface WebSocketChatSessionHeartBeatMessage {
    /**
     * 用户是否正在进行输入操作
     */
    typing: boolean;
}

/**
 * WebSocket ACK对象
 */
export interface WebSocketAckDTO {
    /**
     * ACK消息ID
     */
    ackMessageId: string;

    /**
     * 发送时间
     */
    sendTime: string;
}
